package grammar.parser;

import execution.Executable;
import word.parser.WordElement;

import java.util.ArrayList;
import java.util.List;

public abstract class Decl extends GrammarParser implements Executable {
    private final boolean isConst;
    private final String ident;
    private final int dimension;
    private final List<Integer> lenOfDimension;

    public Decl(boolean isConst, String ident, int dimension, List<Integer> lenOfDimension) {
        this.isConst = isConst;
        this.ident = ident;
        this.dimension = dimension;
        this.lenOfDimension = lenOfDimension;
    }

    public static List<Decl> buildDecl() {
        List<Decl> ans = new ArrayList<>();
        if (getAnalyzingWord().getType() == WordElement.WordType.CONSTTK) {
            ans.addAll(ConstDecl.buildConstDecl());
        } else {
            ans.addAll(VarDecl.buildVarDecl());
        }
        return ans;
    }

    public boolean isConst() {
        return isConst;
    }

    public String getIdent() {
        return ident;
    }

    public int getDimension() {
        return dimension;
    }

    public List<Integer> getLenOfDimension() {
        return lenOfDimension;
    }
}
